#include <arpa/inet.h>
#include <assert.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

#ifndef PROTOCOL_H
#define PROTOCOL_H

/* PORTS **********************************************************************/

#define TCPD_LOCAL 50000
#define TCPD_REMOTE 50001
#define TROLL_PORT 40000

/* PROTOCOL *******************************************************************/

#define NET_HEADER    (sizeof(tcpd_container) - MAX_FILE_DATA)
#define MAX_FILE_DATA 1000
#define MAX_FILENAME 20

typedef struct transfer_header {
    uint32_t size;
    char name[MAX_FILENAME];
} transfer_header;

typedef struct tcpd_container {
    struct sockaddr_in troll;
    struct sockaddr_in dest;
    uint32_t seq;
    uint32_t checksum;
    uint8_t flags;
    uint8_t data[MAX_FILE_DATA];
} tcpd_container;

#define FIN 1
#define ACK 16

/* API ************************************************************************/

int SOCKET();
int BIND(int, char*, unsigned short);
int ACCEPT(int);
int CONNECT(int, char*, char*);
size_t SEND(int, void*, size_t);
size_t RECV(int, void*, size_t);
int CLOSE(int);

#endif
